<template>
  <div class="app-container customer-div">
    <el-tabs v-model="activeName">
      <el-tab-pane label="全部" name="first">
        <div style="margin-top: 40px">
          <!--搜索-->
          <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
            <el-form-item label="单据编号：">
              <el-input v-model="listQuery.entrySn"></el-input>
            </el-form-item>
            <el-form-item label="供应商：">
              <el-select
                clearable
                v-model="listQuery.supplierId"
                filterable
                reserve-keyword
                placeholder="请输入关键词">
                <el-option
                  v-for="item in options2"
                  :key="item.supplierId"
                  :label="item.supplierName"
                  :value="item.supplierId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="单据类型：">
              <el-select v-model="listQuery.entryType"  placeholder="请选择" clearable>
                <el-option
                  key="buy"
                  label="入库单"
                  value="buy">
                </el-option>
                <el-option
                  key="return"
                  label="退货单"
                  value="return">
                </el-option>
                <el-option
                  key="in"
                  label="其它入库单"
                  value="in">
                </el-option><el-option
                key="out"
                label="其它出库单"
                value="out"></el-option>
                <el-option
                  key="loss"
                  label="盘亏单"
                  value="loss">
                </el-option>
                    <el-option
                      key="win"
                      label="盘盈单"
                      value="win">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="采购订单号：">
              <el-input v-model="listQuery.orderSn"></el-input>
            </el-form-item>
            <el-form-item label="合同公司：">
              <el-input v-model="listQuery.fromCompany"></el-input>
            </el-form-item>
            <el-form-item label="单据日期：" >
              <el-date-picker
                :default-time="['00:00:00', '23:59:59']"
                v-model="listQuery.createTime"
                type="daterange"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="业务员：">
              <el-select v-model="listQuery.userId" filterable placeholder="请选择" clearable>
                <el-option
                  v-for="item in userOptionList"
                  :key="item.userId"
                  :label="item.userName"
                  :value="item.userId">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="有无运费：">
              <el-select v-model="listQuery.hasFreight" filterable placeholder="请选择" clearable>
                <el-option
                  :key="0"
                  label="无"
                  :value="0">
                </el-option>
                <el-option
                  :key="1"
                  label="有"
                  :value="1">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="有无票据：">
              <el-select v-model="listQuery.isHasBill" filterable placeholder="请选择" clearable>
                <el-option
                  :key="0"
                  label="无"
                  :value="0">
                </el-option>
                <el-option
                  :key="1"
                  label="有"
                  :value="1">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="是否打印：" >
              <el-select v-model="listQuery.isHasPrint" filterable placeholder="请选择" clearable>
                <el-option :key="1" label="是" :value="1"></el-option>
                <el-option :key="0" label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="牌号：">
              <el-select v-model="listQuery.goodsSn" filterable placeholder="请选择" clearable>
                <el-option
                  v-for="item in goodsList"
                  :key="item.goodsSn"
                  :label="item.goodsSn"
                  :value="item.goodsSn">
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button
                @click="handleSearchList()"
                type="primary">
                查询
              </el-button>
              <el-button
                v-if="inWarehouseExport"
                @click="downloadExcel"
                type="primary">
                导出
              </el-button>
              <el-button
                @click="batchPrinting"
                type="primary">
                批量打印
              </el-button>
            </el-form-item>
          </el-form>
        </div>

        <!--数据列表-->
        <div class="table-container">
          <el-table
            ref="multipleTable"
            row-key="entryId"
            @selection-change="handleSelectionChange"
            v-loading="listLoading"
            :data="tableData"
            border
            style="width: 100%; margin-top: 20px">
            <el-table-column type="selection" :reserve-selection="true" width="60" align="center" fixed="left"></el-table-column>
            <el-table-column  label="单据类型" width="100" align="center" prop="entryType">
            </el-table-column>
            <el-table-column  label="单据编号" width="150" align="center" prop="entrySn">
            </el-table-column>
            <el-table-column  label="单据日期" width="100" align="center" prop="createTime">
            </el-table-column>
            <el-table-column  label="采购订单号" width="150" align="center" prop="orderSn">
              <template slot-scope="scope">
                <el-link @click="toPurchaseContractDetail(scope.row.orderSn)" type="primary" style="font-size:12px">
                  {{scope.row.orderSn}}
                </el-link>
              </template>
            </el-table-column>
            <el-table-column  label="供应商名称" width="300" align="center">
              <template slot-scope="scope">
                {{scope.row.supplierName}}
              </template>
            </el-table-column>
            <el-table-column  label="商品名称" width="300" align="center" class-name="cspantd">
              <template slot-scope="scope">
                <div class="tdDiv" v-for="(item,index) in scope.row.detailList" :style="{'border-bottom': index==scope.row.detailList.length-1 ? '0px solid #EBEEF5' : '1px solid #EBEEF5',}">
                  {{item.goodsSn}}
                </div>
              </template>
            </el-table-column>
            <el-table-column  label="仓库" width="150" align="center" class-name="cspantd">
              <template slot-scope="scope">
                <div class="tdDiv" v-for="(item,index) in scope.row.detailList" :style="{'border-bottom': index==scope.row.detailList.length-1 ? '0px solid #EBEEF5' : '1px solid #EBEEF5',}">
                  {{item.warehouse}}
                </div>
              </template>
            </el-table-column>
            <el-table-column  label="数量" width="100" align="center" class-name="cspantd">
              <template slot-scope="scope">
                <div class="tdDiv" v-for="(item,index) in scope.row.detailList" :style="{'border-bottom': index==scope.row.detailList.length-1 ? '0px solid #EBEEF5' : '1px solid #EBEEF5',}">
                  {{item.goodsNum}}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              label="交（提）方式，地点"
              align="center"
              width="100">
              <template slot-scope="scope">
                {{scope.row.sendType}}
              </template>
            </el-table-column>
            <el-table-column  label="结算方式" width="100" align="center">
              <template slot-scope="scope">
                {{scope.row.settleType}}
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="费用承担"
              width="100">
              <template slot-scope="scope">
                {{scope.row.freightType}}
              </template>
            </el-table-column>
            <el-table-column
              label="合同公司"
              align="center"
              width="100">
              <template slot-scope="scope">
                {{scope.row.fromCompany}}
              </template>
            </el-table-column>
            <el-table-column
              label="数量"
              align="center"
              width="100">
              <template slot-scope="scope">
                {{scope.row.entryNum}}
              </template>
            </el-table-column>
            <!--        <el-table-column-->
            <!--                prop="entryAmount"-->
            <!--                label="金额"-->
            <!--                width="100"-->
            <!--                align="center">-->
            <!--        </el-table-column>-->
            <el-table-column
              label="业务员"
              width="100"
              align="center">
              <template slot-scope="scope">
                {{scope.row.userName}}
              </template>
            </el-table-column>
            <el-table-column
              label="运费"
              width="100"
              align="center">
              <template slot-scope="scope">
                {{scope.row.freight}}
              </template>
            </el-table-column>
            <el-table-column
              label="司机运费"
              width="100"
              align="center">
              <template slot-scope="scope">
                {{scope.row.driverFreight}}
              </template>
            </el-table-column>
            <el-table-column
              label="有无票据"
              width="100"
              align="center">
              <template slot-scope="scope">
                {{scope.row.isHasBill == 1 ? '有票据' : '无票据'}}
              </template>
            </el-table-column>
            <el-table-column
              label="物流毛利"
              width="100"
              align="center">
              <template slot-scope="scope">
                {{scope.row.freightProfit}}
              </template>
            </el-table-column>
            <el-table-column
              label="运费报销状态"
              width="100"
              align="center">
              <template slot-scope="scope">
                {{scope.row.isFreightSettled==0 ? '未报销' : '已报销'}}
              </template>
            </el-table-column>
            <el-table-column
              label="备注"
              width="200">
              <template slot-scope="scope">
                {{scope.row.remark}}
              </template>
            </el-table-column>
            <el-table-column
              fixed="right"
              align="center"
              label="操作"
              width="150">
              <template slot-scope="scope">
                <el-button type="text" @click="toDetail(scope.row)">查看</el-button>
                <el-button type="text" @click="showPrint(scope.row)">打印(已打印{{scope.row.hasPrintNum}}次)</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total, sizes,prev, pager, next,jumper"
            :current-page.sync="listQuery.pageNum"
            :page-size="listQuery.pageSize"
            :page-sizes="[10,15,20]"
            :total="count">
          </el-pagination>
        </div>
      </el-tab-pane>
      <el-tab-pane label="入库单承兑不含C" name="second">
        <div style="margin-top: 40px">
          <!--搜索-->
          <el-form :inline="true" :model="listQuery2" size="mini" label-width="100px">
            <el-form-item label="单据日期：" >
              <el-date-picker
                :default-time="['00:00:00', '23:59:59']"
                v-model="listQuery2.createTime"
                type="daterange"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button
                @click="handleSearchList2()"
                type="primary">
                查询
              </el-button>
            </el-form-item>
          </el-form>
        </div>
        <!--数据列表-->
        <div class="table-container">
          <el-table
            v-loading="listLoading2"
            :data="tableData2"
            border
            style="width: 100%; margin-top: 20px">
            <el-table-column  label="单据编号" min-width="150" align="center" prop="entrySn">
            </el-table-column>
            <el-table-column  label="单据日期" min-width="100" align="center" prop="entryTime">
            </el-table-column>
            <el-table-column  label="采购订单号" min-width="150" align="center" prop="purchaseOrderSn"></el-table-column>
            <el-table-column  label="供应商名称" min-width="300" align="center">
              <template slot-scope="scope">
                {{scope.row.supplierName}}
              </template>
            </el-table-column>
            <el-table-column  label="商品名称" min-width="300" align="center" >
              <template slot-scope="scope">
                  {{scope.row.goodsName}}
              </template>
            </el-table-column>
            <el-table-column  label="数量" min-width="100" align="center" >
              <template slot-scope="scope">
                  {{scope.row.goodsNum}}
              </template>
            </el-table-column>
            <el-table-column  label="批号" min-width="150" align="center">
              <template slot-scope="scope">
                {{scope.row.goodsBatchNo}}
              </template>
            </el-table-column>

          </el-table>
        </div>
        <div class="pagination-container">
          <el-pagination
            background
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"
            layout="total, sizes,prev, pager, next,jumper"
            :current-page.sync="listQuery2.pageNum"
            :page-size="listQuery2.pageSize"
            :page-sizes="[10,15,20]"
            :total="count2">
          </el-pagination>
        </div>
      </el-tab-pane>

    </el-tabs>


    <!--打印弹窗-->
    <el-dialog
            title="打印"
            :close-on-click-modal="false"
            :beforeClose="closePrint"
            :visible.sync="dialogVisible4"
            width="900px">
      <div id="print-div">
        <div class="title">{{orderInfo.fromCompanyName}}{{orderInfo.entryType}}</div>
        <div class="paper-top">
          <el-row>
            <el-col :span="10"><span>编号：{{orderInfo.entrySn}}</span></el-col>
            <el-col :span="14"><span>单据日期：{{orderInfo.createTime}}</span></el-col>
          </el-row>
          <el-row>
            <el-col :span="24"><span>供应商：{{orderInfo.supplierName}}</span></el-col>
          </el-row>
        </div>
        <div class="good-table" style="margin-top:0">
          <table cellspacing="0" cellpadding="0" border="0" width="100%">
            <tr>
              <th align="center" width="12.5%"><div style="white-space:nowrap;">商品名称</div></th>
              <th align="center" width="17%"><div style="white-space:nowrap;">规格型号</div></th>
              <th align="center" width="3%"><div style="white-space:nowrap;">单位</div></th>
              <th align="center" width="10%"><div style="white-space:nowrap;">数量</div></th>
              <th align="center" width="10%"><div style="white-space:nowrap;">单价</div></th>
              <th align="center" width="10%"><div style="white-space:nowrap;">总额</div></th>
              <th align="center" width="12.5%"><div style="white-space:nowrap;">批号</div></th>
              <th align="center" width="12.5%"><div style="white-space:nowrap;">仓库</div></th>
              <th align="center" width="12.5%"><div style="white-space:nowrap;">合同单号</div></th>
              <th align="center" ><div style="white-space:nowrap;">备注</div></th>
            </tr>
            <tr v-for="item in orderInfo.entryGoodsList">
              <td align="center"><div style="word-break:break-all">{{item.goodsName}}</div></td>
              <td align="center"><div style="word-break:break-all">{{item.goodsSn}}</div></td>
              <td align="center" style="white-space:nowrap;width:50px">{{item.goodsUnit}}<div></div></td>
              <td align="center" style="white-space:nowrap;"><div>{{item.goodsNum}}</div></td>
              <td align="center" style="white-space:nowrap;"><div>{{item.goodsPrice}}</div></td>
              <td align="center" style="white-space:nowrap;"><div>{{item.goodsAmount}}</div></td>
              <td align="center" style="white-space:nowrap;"> <div>{{item.goodsBatchNo}}</div></td>
              <td align="center"><div style="white-space:nowrap;">{{item.goodsWarehouse}}</div></td>
              <td align="center"><div style="white-space:nowrap;">{{item.orderSn}}</div></td>
              <td align="center"><div style="word-break:break-all;min-width:60px">{{item.goodsRemark}}</div></td>
            </tr>
            <tr>
              <td colspan="3" align="center">数量合计</td>
              <td colspan="7">{{orderInfo.entryNum}}</td>
            </tr>
          </table>
        </div>
        <div class="paper-bottom">
          <el-row style="margin-top:20px">
            <el-col :span="6"><span>仓库签收</span></el-col>
            <el-col :span="9" style="text-align: center"><span>业务员：{{orderInfo.userName}}</span></el-col>
            <el-col :span="9" style="text-align: right"><span>制单：{{orderInfo.createUserName}}</span></el-col>
          </el-row>
          <el-row style="margin-top:10px">
            <el-col :span="24">注：本单白色联为（采购联），红色为（仓库联），蓝色为(财务联),绿单为(存根联)，黄色为(存根联)</el-col>
          </el-row>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" size="small" style="width:150px;" @click="printdiv">打印</el-button>
      </div>
    </el-dialog>

    <!--批量打印弹窗-->
    <el-dialog
      title="批量打印"
      :close-on-click-modal="false"
      :beforeClose="closePrint2"
      :visible.sync="dialogVisible5"
      width="900px">
      <div style="max-height:400px;overflow-y: auto;">
        <div id="print-div2" >
          <div v-for="orderInfo in list" style="page-break-after: always;">
            <div class="title">{{orderInfo.fromCompanyName}}{{orderInfo.entryType}}</div>
            <div class="paper-top">
              <el-row>
                <el-col :span="10"><span>编号：{{orderInfo.entrySn}}</span></el-col>
                <el-col :span="14"><span>单据日期：{{orderInfo.createTime}}</span></el-col>
              </el-row>
              <el-row>
                <el-col :span="24"><span>供应商：{{orderInfo.supplierName}}</span></el-col>
              </el-row>
            </div>
            <div class="good-table" style="margin-top:0">
              <table cellspacing="0" cellpadding="0" border="0" width="100%">
                <tr>
                  <th align="center" width="12.5%"><div style="white-space:nowrap;">商品名称</div></th>
                  <th align="center" width="17%"><div style="white-space:nowrap;">规格型号</div></th>
                  <th align="center" width="3%"><div style="white-space:nowrap;">单位</div></th>
                  <th align="center" width="10%"><div style="white-space:nowrap;">数量</div></th>
                  <th align="center" width="10%"><div style="white-space:nowrap;">单价</div></th>
                  <th align="center" width="10%"><div style="white-space:nowrap;">总额</div></th>
                  <th align="center" width="12.5%"><div style="white-space:nowrap;">批号</div></th>
                  <th align="center" width="12.5%"><div style="white-space:nowrap;">仓库</div></th>
                  <th align="center" width="12.5%"><div style="white-space:nowrap;">合同单号</div></th>
                  <th align="center" ><div style="white-space:nowrap;">备注</div></th>
                </tr>
                <tr v-for="item in orderInfo.entryGoodsList">
                  <td align="center"><div style="word-break:break-all">{{item.goodsName}}</div></td>
                  <td align="center"><div style="word-break:break-all">{{item.goodsSn}}</div></td>
                  <td align="center" style="white-space:nowrap;width:50px">{{item.goodsUnit}}<div></div></td>
                  <td align="center" style="white-space:nowrap;"><div>{{item.goodsNum}}</div></td>
                  <td align="center" style="white-space:nowrap;"><div>{{item.goodsPrice}}</div></td>
                  <td align="center" style="white-space:nowrap;"><div>{{item.goodsAmount}}</div></td>
                  <td align="center" style="white-space:nowrap;"> <div>{{item.goodsBatchNo}}</div></td>
                  <td align="center"><div style="white-space:nowrap;">{{item.goodsWarehouse}}</div></td>
                  <td align="center"><div style="white-space:nowrap;">{{item.orderSn}}</div></td>
                  <td align="center"><div style="word-break:break-all;min-width:60px">{{item.goodsRemark}}</div></td>
                </tr>
                <tr>
                  <td colspan="3" align="center">数量合计</td>
                  <td colspan="7">{{orderInfo.entryNum}}</td>
                </tr>
              </table>
            </div>
            <div class="paper-bottom">
              <el-row style="margin-top:20px">
                <el-col :span="6"><span>仓库签收</span></el-col>
                <el-col :span="9" style="text-align: center"><span>业务员：{{orderInfo.userName}}</span></el-col>
                <el-col :span="9" style="text-align: right"><span>制单：{{orderInfo.createUserName}}</span></el-col>
              </el-row>
              <el-row style="margin-top:10px">
                <el-col :span="24">注：本单白色联为（采购联），红色为（仓库联），蓝色为(财务联),绿单为(存根联)，黄色为(存根联)</el-col>
              </el-row>
            </div>
          </div>

        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="primary" size="small" style="width:150px;" @click="printdiv2">打印</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
  import {entryPrintContentBatch,entryBatchNoDiff,getOrderUsersList,getDeliverDetailList,supplierList,entryList,entryDetail,warehouseUpdatePrintNum,orderGoodsList} from '@/api/partner'
  import {formatDate} from '@/utils/date';
  import store from '@/store'
  import { mapGetters } from 'vuex'
  // import "@/utils/jQuery.print"
  const defaultListQuery={
    pageNum: 1,
    pageSize: 10,
    entryType: '',
    entrySn:null,
    orderSn:null,
    supplierId:null,
    fromCompany:'',
    userId:'',
    createTime:null,
    hasFreight:null,
    isHasBill:'',
    isHasPrint:'',
    goodsSn:''
  };
  const defaultListQuery2={
    pageNum: 1,
    pageSize: 10,
    createTime:null,
  };
  export default {
    name: "index",
    data(){
      return {
        listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
        tableData: [],
        count: 0,
        listLoading: false,

        listQuery2: JSON.parse(JSON.stringify(defaultListQuery2)),
        tableData2: [],
        count2: 0,
        listLoading2: false,

        roles:store.getters.roles ? store.getters.roles : [],
        userOptionList:[],
        options2:[],
        dialogVisible4:false,
        orderInfo:{},
        printEntryId:'',
        selectProduct:[],
        dialogVisible5:false,
        list:[],
        activeName:'first',
        goodsList:[]
      }
    },
    computed: {
      ...mapGetters([
        'name',
        'mobile',
        'userId'
      ]),
      inWarehouseExport(){
        if(this.roles.indexOf("inWarehouseExport") != -1){
          return true
        }else{
          return false
        }
      },

    },
    created() {
      let now = new Date();
      let nowMonth = now.getMonth(); //当前月
      let nowYear = now.getFullYear(); //当前年
      //本月的开始时间
      let monthStartDate = new Date(nowYear, nowMonth, 1);
      //本月的结束时间
      let monthEndDate = new Date(nowYear, nowMonth+1, 0,23,59,59);
      let startDate = formatDate(monthStartDate, 'yyyy-MM-dd');
      let endDate = formatDate(monthEndDate, 'yyyy-MM-dd');
      this.listQuery2.createTime = [startDate,endDate];
      this.getList();
      this.getList2();
      this.getUserOptionList();
      this.getSupplierList();
      orderGoodsList().then((res)=>{
        this.goodsList = res.list
      })
    },
    filters: {
      formatCreateTime(time) {
        if(time){
          let date = new Date(time);
          return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
        }else{
          return '--'
        }
      },
    },
    methods:{

      handleSizeChange2(val){
        this.listQuery2.pageNum = 1;
        this.listQuery2.pageSize = val;
        this.getList2();
      },
      handleCurrentChange2(val){
        this.listQuery2.pageNum = val;
        this.getList2();
      },

      handleSearchList2(){
        this.listQuery2.pageNum = 1;
        this.getList2();
      },

      //获取发货明细列表
      getList2() {
        this.listLoading2 = true;
        return entryBatchNoDiff(this.listQuery2).then(response => {
          this.tableData2 = response.list;
          this.count2 = response.count;
          this.listLoading2 = false;
        }).catch(()=>{
          this.listLoading2 = false;
        });
      },


      //切换选择单据
      handleSelectionChange(val){
        console.log("val",JSON.parse(JSON.stringify(val)))
        this.selectProduct = JSON.parse(JSON.stringify(val));
      },

      //去采购详情页
      toPurchaseContractDetail(orderSn){
        let routeData = this.$router.resolve({name:'purchaseContractDetail',query:{id:orderSn}});
        window.open(routeData.href);
      },

      batchPrinting(){
        if(this.selectProduct.length > 0){
          this.dialogVisible5 = true;
          let entryIds = [];
          this.selectProduct.forEach((el)=>{
            entryIds.push(el.entryId)
          })
          entryPrintContentBatch({entryIds:entryIds.join(",")}).then((res)=>{
            this.list = res
          })
        }else{
          this.$message({
            type: 'info',
            message: '请先选择单据'
          });
        }
      },


      //关闭打印弹窗
      closePrint2(){
        this.dialogVisible5 = false;
        this.getList().then(()=>{
          this.$nextTick(() => {
            this.$refs.multipleTable.clearSelection();
            this.selectProduct = [];
            this.$forceUpdate()
          })
        });
      },

      //打印
      printdiv2(){
        let entryIds = [];
        this.selectProduct.forEach((el)=>{
          entryIds.push(el.entryId)
        })
        console.log("entryIds",entryIds)
        warehouseUpdatePrintNum({entryId:entryIds.join(",")});
        $("#print-div2").print({
          globalStyles:true,//是否包含父文档的样式，默认为true
          mediaPrint:true,//是否包含media='print'的链接标签。会被globalStyles选项覆盖，默认为false
          stylesheet:null,//外部样式表的URL地址，默认为null
          noPrintSelector:".no-print",//不想打印的元素的jQuery选择器，默认为".no-print"
          iframe:true,//是否使用一个iframe来替代打印表单的弹出窗口，true为在本页面进行打印，false就是说新开一个页面打印，默认为true
          append:null,//将内容添加到打印内容的后面
          prepend:null,//将内容添加到打印内容的前面，可以用来作为要打印内容
          deferred: $.Deferred()//回调函数
        });
      },

      //显示打印弹窗
      showPrint(item){
        this.dialogVisible4 = true;
        this.printEntryId = item.entryId;
        entryDetail({entryId:item.entryId}).then(res=>{
          this.orderInfo = res;
        });
      },

      //关闭打印弹窗
      closePrint(){
        this.dialogVisible4 = false;
        this.getList()
      },

      //打印
      printdiv(){
        warehouseUpdatePrintNum({entryId:this.printEntryId});
        $("#print-div").print({
          globalStyles:true,//是否包含父文档的样式，默认为true
          mediaPrint:true,//是否包含media='print'的链接标签。会被globalStyles选项覆盖，默认为false
          stylesheet:null,//外部样式表的URL地址，默认为null
          noPrintSelector:".no-print",//不想打印的元素的jQuery选择器，默认为".no-print"
          iframe:true,//是否使用一个iframe来替代打印表单的弹出窗口，true为在本页面进行打印，false就是说新开一个页面打印，默认为true
          append:null,//将内容添加到打印内容的后面
          prepend:null,//将内容添加到打印内容的前面，可以用来作为要打印内容
          deferred: $.Deferred()//回调函数
        });
      },

      //查看发货单
      toDetail(item){
        let routeData = this.$router.resolve({name:'inWarehouseDetail',query:{id:item.entryId}});
        window.open(routeData.href);
      },
      //供应商
      getSupplierList() {
        supplierList().then((res)=>{
          this.options2 = res;
        })
      },


      //获取员工下拉选项
      getUserOptionList(){
        getOrderUsersList().then((res)=>{
          this.userOptionList = res;
        })
      },

      //选择员工名称
      handleSelectUserName(key,item){
        this.listQuery[key] = item.userId;
      },


      handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      },

      handleSearchList(){
        this.listQuery.pageNum = 1;
        this.getList();
      },

      //获取发货明细列表
      getList() {
        this.listLoading = true;
        return entryList(this.listQuery).then(response => {
          this.tableData = response.list;
          this.count = response.count;
          this.listLoading = false;
        }).catch(()=>{
          this.listLoading = false;
        });
      },

      //下载excle
      downloadExcel(){
        let params = JSON.parse(JSON.stringify(this.listQuery));
        params.export = 1;
        entryList(params).then((res)=>{
          require.ensure([], () => {
            const { export_json_to_excel } = require('sheet/Export2Excel');
            const tHeader = res.title;
            const filterVal = res.columns;
            const list = res.list;
            const data = this.formatJson(filterVal, list);
            export_json_to_excel(tHeader, data, res.fileName);
          })
        })
      },

      //下载表格数据格式化
      formatJson(filterVal, jsonData) {
        return jsonData.map(v => filterVal.map(j => v[j]))
      },

    },
  }
</script>

<style  lang="scss">
  .upload-div{
    text-align: center;
    position:relative;
    #upload{

      opacity: 0;
      position: absolute;
      z-index: 1;
      width:154px;
      height:40px
    }
  }
  .cspantd{
    padding:0 !important;
    .cell{
      padding:0 !important;
      .tdDiv{
        padding:5px 10px;
        min-height: 20px;
        line-height: 20px;
        box-sizing: content-box;
      }
    }
  }

  #print-div,#print-div2{
    font-size:14px;
    font-family: "Microsoft YaHei";
    color:#000;
    width:100%;
    margin:0 auto;
    .title{
      font-size:28px;
      font-weight: bold;
      text-align: center;
      line-height: 40px;
    }
    .paper-top{
      margin-top:20px;
      line-height: 20px;
    }
    .good-table{
      width:100%;
      margin-top:0px;
      table{
        border-left:1px solid #000;
        border-bottom:1px solid #000;
        td,th{
          font-weight: normal;
          border-right:1px solid #000;
          border-top:1px solid #000;
          padding:5px 10px;
          line-height: 20px;
        }
      }
    }
    .paper-bottom{
      margin-top:0px;
      line-height: 20px;
    }
  }
</style>
